package com.apestech.api.xml.esb.modul;

import com.apestech.api.condition.ConditionStrategyExec;
import com.apestech.framework.db.SqlSession;
import com.apestech.framework.json.JSONArray;
import com.apestech.framework.json.JSONObject;
import com.apestech.framework.util.DataMappingUtil;
import com.apestech.framework.xml.condition.modul.Condition;

/**
 * @author hup
 * @create 2019-10-10-16:33
 */
public class EsbForm extends DataMappingUtil {

    private SqlSession session;

    public SqlSession getSession() {
        return session;
    }

    public void setSession(SqlSession session) throws Exception {
        this.session = session;
    }

    public JSONObject getSearchForm(String id, JSONObject input) throws Exception {
        EsbFormPop form=new EsbFormPop(session, id, input);
        return form.getSearchForm();
    }

    public JSONArray getConditionField(Condition condition, String mid, JSONObject fieldJson) throws Exception {
        EsbFormCondition form=new EsbFormCondition(condition, mid, "zd");
        JSONArray flist=form.getConditionField();
        return flist;
    }

    public JSONArray getImportConditionField(Condition condition, String mid, JSONObject fieldJson) throws Exception {
        EsbFormCondition form=new EsbFormCondition(condition, mid, "imp");
        return form.getImportConditionField();
    }

    public JSONObject getQryConditionField(Condition condition, String tabId, JSONObject input, JSONObject fieldJson) throws Exception {
        EsbFormPop form=new EsbFormPop(session, tabId, input);
        String query=input.getString("query");
        if("bill".equals(query) || "billpop".equals(query)){
            return form.getConditionQry(condition, tabId, fieldJson);
        } else if("exec".equals(query)){
            return form.getConditionEQry(condition, tabId, fieldJson);
        }
        return null;
    }

    public JSONObject getQryConditionField_esb(Condition condition, String tabId, JSONObject input, JSONObject fieldJson) throws Exception {
        EsbFormPop form=new EsbFormPop(session, tabId, input);
        form.setEsb(true);
        String query=input.getString("query");
        if("bill".equals(query) || "billpop".equals(query)){
            return form.getConditionQry_esb(condition, tabId, fieldJson);
        } else if("exec".equals(query)){
            return form.getConditionEQry_esb(condition, tabId, fieldJson);
        }
        return null;
    }

    public JSONObject getConditionFields(Condition condition, String mid, JSONObject fieldJson) throws Exception {
        EsbFormCondition form=new EsbFormCondition(condition, mid, "zd");
        return form.getConditionFields();
    }

    public JSONArray getStopConditionField(Condition condition, String mid, JSONObject out) throws Exception {
        EsbFormCondition form=new EsbFormCondition(condition, mid, "stop");
        out=form.getOutput();
        return form.getStopConditionField();
    }

    public JSONObject getStrategyFields(ConditionStrategyExec strategyExec) throws Exception {
        EsbFormStrategy form=new EsbFormStrategy(strategyExec);
        return form.getAllInput();
    }

}
